package com.xuyoupeng.springlearn.bean.common;

import com.xuyoupeng.springframework.beans.BeansException;
import com.xuyoupeng.springframework.beans.PropertyValue;
import com.xuyoupeng.springframework.beans.PropertyValues;
import com.xuyoupeng.springframework.beans.factory.config.BeanDefinition;
import com.xuyoupeng.springframework.beans.factory.config.BeanFactoryPostProcessor;
import com.xuyoupeng.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * @author xuyoupneg
 * @description TODO
 * @date 2024/3/22 15:11
 */
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition("userService");
        PropertyValues propertyValues = beanDefinition.getPropertyValues();
        //添加一个propertyValues中已存在name的PropertyValue,在getBean设置属性信息的时候会把排在前面的通name的value覆盖掉
        propertyValues.addPropertyValue(new PropertyValue("age", "10"));
    }
}
